$(function () {
    const outlineDemoApi = api.outlineDemo;

    layui.config({
        base: '/layui/lay/modules/'
    }).extend({
        treetable: 'treetable-lay/treetable'
    }).use(['treetable','table', 'layer', 'form', 'laypage', 'laydate'], function () {
        var table = layui.table //表格
            , layer = layui.layer //弹层
            , form = layui.form //form表单
            , laypage = layui.laypage //分页
            , laydate = layui.laydate//日期
            ,treetable = layui.treetable;

        //第一个实例
        table.render({
            elem: '#demo'
            , id: 'tableReload'
            // ,height: 312
            , url: '/api/outline/outlineQueryAll' //数据接口
            , request: {
                pageName: 'page' //页码的参数名称，默认：page
                , limitName: 'size' //每页数据量的参数名，默认：limit
            }
            , limit: 5
            , page: {
                curr: 1
            } //开启分页
            ,  cols: [[ //表头
                {field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left'}
                , {field: 'name', title: '名称', width: 270}
                , {title: '课程', width: 150, templet: "<div>{{d.course.name}}</div>"}
                , {title: '年级', width: 100, templet: "<div>{{d.course.grade.name}}</div>"}
                , {title: '状态', width: 100,
                    templet: "<div>{{d.status?`<span style='color:green'>审核通过</span>`:`<span style='color:red'>待审核</span>`}}</div>"}
                , {fixed: 'right', width: 100, align: 'center', toolbar: '#oper-col'}
            ]]
            , title: '图文文字管理'
        });

        // 查看
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'detail':
                    renderTable(data.content);
                    detail('大纲详情', 800, 600)
                    break;
            }
        });

        var renderTable = function (data) {
            // layer.load(2);
            treetable.render({
                treeColIndex: 0,          // treetable新增参数
                treeSpid: -1,             // treetable新增参数
                treeIdName: 'd_id',       // treetable新增参数
                treePidName: 'd_pid',     // treetable新增参数
                treeDefaultClose: true,   // treetable新增参数
                treeLinkage: true,        // treetable新增参数
                elem: '#table1',
                data: data,
                cols: [[
                    // {type: 'number'},
                    // {field: 'id', title: 'id'},
                    {field: 'num', title: '标号', width: 150},
                    {field: 'name', title: '名称', width: 225},
                    {field: 'intro', title: '介绍', width: 350},
                ]]
            });
        };
        var getOutline = async () => {
            const res = await outlineDemoApi();
            renderTable(res.data.content);
        }
        getOutline();
    });

})